﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ChatBox.Utilities;
using ChatBox.Commands;

namespace ChatBox.Models
{
  public class MessageRepository : NotificationObject
  {
    #region Constructors

    public MessageRepository()
      : base()
    {
      _sendCommand = new SimpleCommand<String>( this.SendHandler, this.CanSend );
    }

    #endregion

    #region Public Properties

    public String Name
    {
      get
      {
        return _name;
      }
      set
      {
        if ( _name != value )
        {
          _name = value;

          this.OnPropertyChanged( "Name" );
        }
      }
    }

    public ViewableCollection<MessageInfo> Messages
    {
      get
      {
        return _messages;
      }
    }

    public String Message
    {
      get
      {
        return _message;
      }
      set
      {
        if ( value != _message )
        {
          _message = value;

          this.OnPropertyChanged( "Message" );
        }
      }
    }

    public ICommand Send
    {
      get
      {
        return _sendCommand;
      }
    }

    #endregion

    #region Private Methods

    private void SendHandler( String _message )
    {
      Console.WriteLine( _message );
    }

    private Boolean CanSend( String _message )
    {
      return !String.IsNullOrEmpty( _message );
    }

    #endregion

    #region Private Variables

    private String _name = String.Empty;

    private readonly ViewableCollection<MessageInfo> _messages = new ViewableCollection<MessageInfo>();

    private String _message = String.Empty;

    private readonly SimpleCommand<String> _sendCommand;

    #endregion
  }
}
